#include <iostream>
#include <iomanip>
#include <ctime>
#include <stdlib.h>

using namespace std;

#define MaxSize         52

struct SeqStack{
    int data[MaxSize];
    int top;
};

void Create(SeqStack &S){
    S.top=-1;
}

int IsEmpty(const SeqStack& S)
{
    if(S.top==-1)return 1;
    return 0;
}

int IsFull(const SeqStack& S)
{
    if(S.top>=MaxSize-1) return 1;
    return 0;
}

void Push(SeqStack& S, int x)
{
    if(IsFull(S))
    {
        cout<<"栈满\n";
        return ;
    }
    S.data[++S.top] = x;
}

void Pop(SeqStack& S, int &x)
{
    if(IsEmpty(S))
    {
        cout<<"栈空\n";
        return ;
    }
    x = S.data[S.top--];
}

void WashCard(int card[])
{
    int i,j,k,tmp;
    for(k=0;k<MaxSize;k++)
    {
        for(i=0;i<MaxSize-1;i++)
        {
            for(j=i;j<MaxSize;j++)
            {
                if(rand()%MaxSize == 2)
                {
                    tmp = card[i];
                    card[i] = card[j];
                    card[j] = tmp;
                }
            }
        }
    }
}

void GiveCard(SeqStack S)
{
    char AscCode;
    int style,ColNum=0,x;
    cout<<"顺时针发牌，显示各家牌面\n";
    cout<<"东家\t南家\t西家\t北家\n";
    cout<<"===================================================================\n";
    while(!IsEmpty(S))
    {
        Pop(S,x);
        style = x/13;
        switch(style)
        {
            case 0:
                AscCode = 5; break;
            case 1:
                AscCode = 4; break;
            case 2:
                AscCode = 3; break;
            case 3:
                AscCode = 6; break;
        }
        cout<<"["<<AscCode<<setw(3)<<x%13+1<<"]\t";
        ColNum++;
        if(ColNum == 4)
        {
            cout<<endl;
            ColNum=0;
        }
    }
}

/**
 * @brief 十进制转N进制
 * 
 */
void MultibaseOutput(unsigned int data, int N, std::string& result)
{
    SeqStack S;
    Create(S);
    int xx = data;
    while (xx)
    {
        int quotient = xx/N;
        int remainder = xx%N;
        Push(S, remainder);
        xx = quotient;
    }

    while (!IsEmpty(S))
    {
        int tmp;
        Pop(S, tmp);
        if (tmp<10)
        {
            result.push_back(tmp+'0');
        }
        else
        {
            result.push_back(tmp+'A'-10);
        }
    }
}


int main()
{
    std::string result;
    MultibaseOutput(123, 16, result);
    printf("%s\n", result.c_str());
    // int card[MaxSize];
    // srand(time(NULL));
    // for(int i=0;i<MaxSize;i++) card[i] = i;
    // WashCard(card);
    // SeqStack S;
    // Create(S);
    // for(int i=0;i<MaxSize;i++) Push(S,card[i]);
    // GiveCard(S);
}
